package com.by.controller;


import com.by.bean.PayInfo;
import com.by.core.bean.ResultBean;
import com.by.core.controller.BaseController;
import com.by.core.group.ISave;
import com.by.core.group.V;
import com.by.service.PayInfoService;
import com.by.utils.ACode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Hzy
 * @version 1.0
 * @date 2025/4/14  16:45
 * @description
 * @since jdk11
 */

@RestController
@RequestMapping("/api")
@Api(tags = "查询支付宝支付服务")
public class QueryAliPayController extends BaseController {
    @Autowired
    PayInfoService aliPayService;

    @ApiOperation("保存支付信息")
    @PostMapping("/save")
    public ResultBean save(@Validated(ISave.class) @RequestBody PayInfo payInfo, BindingResult result) {
        V.validate(result);
        payInfo.setPay_id(ACode.generatePaymentNumber());
        int rs = aliPayService.save(payInfo);
        return success("保存成功",rs);
    }

    @ApiOperation("获取支付信息")
    @GetMapping("/get")
    public ResultBean getAliPayById( Long pay_id) {
        Map map = (Map) aliPayService.get(pay_id);
        if (map == null) {
            return fail("支付信息不存在");
        }
        return success("支付信息", map);
    }

    @ApiOperation("修改支付状态")
    @PutMapping("/update")
    public ResultBean update(@RequestBody PayInfo payInfo) {
        int rs = aliPayService.update(payInfo);
        return success("修改成功", rs);
    }

}
